package jp.ac.u_tokyo.dch.view.outputdata;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import jp.ac.u_tokyo.dch.model.db.Data;
import jp.ac.u_tokyo.dch.model.db.DataDetail;
import jp.ac.u_tokyo.dch.model.db.DataFile;
import jp.ac.u_tokyo.dch.model.db.DataSchemaDetail;
import jp.ac.u_tokyo.dch.view.Constants;
/**
 * @version 1.1
 */
public class DataView {

	/**
	 * データスキーママップ
	 */
	private Map<String, DataSchemaDetail> dataSchemaDetailMap = null;

	/**
	 * データスキーママップ
	 */
	private Map<String, DataDetail> dataDetailMap = null;

	/**
	 * 6段階を識別するID
	 */
	private String sort;

	/**
	 * 親ID
	 */
	private String oyaSort;

	/**
	 * スキーマアイテムリスト
	 */
	private List<DataSchemaDetail> schemaItemList;

	/**
	 * スキーマカスタムリスト
	 */
	private List<DataSchemaDetail> customItemList;

	/**
	 * データ
	 */
	private Data data;

	/**
	 * データ詳細リスト
	 */
	private List<DataDetail> dataDetailList;

	/**
	 *
	 */
	private List<DataDetail> customDataDetailList;

	/**
	 *
	 */
	private List<DataFile> dataFileList = null;

	/**
	 *
	 */
	private String oyaId;

	/**
	 *
	 */
	private String oyaName;

	/**
	 *
	 */
	private DataFile addFileInfo = null;

	/**
	 *
	 */
	private String deleteMutiMediaIndex;

	/**
	 *
	 */
	public DataView() {

		data = new Data();
		schemaItemList = new ArrayList<DataSchemaDetail>();
		customItemList = new ArrayList<DataSchemaDetail>();
		dataFileList = new ArrayList<DataFile>();
	}

	public Data getData() {
		return data;
	}

	public void setData(Data data) {
		this.data = data;
	}

	public List<DataDetail> getDataDetailList() {
		return dataDetailList;
	}

	public void setDataDetailList(List<DataDetail> dataDetailList) {
		this.dataDetailList = dataDetailList;
	}

	public List<DataDetail> getCustomDataDetailList() {
		return customDataDetailList;
	}

	public void setCustomDataDetailList(List<DataDetail> customDataDetailList) {
		this.customDataDetailList = customDataDetailList;
	}

	public List<DataFile> getDataFileList() {
		return dataFileList;
	}

	public void setDataFileList(List<DataFile> dataFileList) {
		this.dataFileList = dataFileList;
	}

	public List<DataSchemaDetail> getSchemaItemList() {
		return schemaItemList;
	}

	public void setSchemaItemList(List<DataSchemaDetail> schemaItemList) {
		this.schemaItemList = schemaItemList;
	}

	public List<DataSchemaDetail> getCustomItemList() {
		return customItemList;
	}

	public void setCustomItemList(List<DataSchemaDetail> customItemList) {
		this.customItemList = customItemList;
	}


	public String getOyaId() {
		return oyaId;
	}

	public void setOyaId(String oyaId) {
		this.oyaId = oyaId;
	}

	public String getOyaName() {
		return oyaName;
	}

	public void setOyaName(String oyaName) {
		this.oyaName = oyaName;
	}

	public String getSort() {
		return sort;
	}

	public String getDeleteMutiMediaIndex() {
		return deleteMutiMediaIndex;
	}

	public void setDeleteMutiMediaIndex(String deleteMutiMediaIndex) {
		this.deleteMutiMediaIndex = deleteMutiMediaIndex;
	}

	public DataFile getAddFileInfo() {
		return addFileInfo;
	}

	public void setAddFileInfo(DataFile addFileInfo) {
		this.addFileInfo = addFileInfo;
	}

	public void setSort(String sort) {
		this.sort = sort;
		if (Constants.LV2_SORT.equals(sort)) {
			oyaSort = Constants.LV1_SORT;
		} else if (Constants.LV3_SORT.equals(sort)) {
			oyaSort = Constants.LV2_SORT;
		} else if (Constants.LV4_SORT.equals(sort)) {
			oyaSort = Constants.LV3_SORT;
		} else if (Constants.LV5_SORT.equals(sort)) {
			oyaSort = Constants.LV4_SORT;
		} else if (Constants.LV6_SORT.equals(sort)) {
			oyaSort = Constants.LV5_SORT;
		} else if (Constants.LV7_SORT.equals(sort)) {
			oyaSort = Constants.LV6_SORT;
		}
	}
	public String getOyaSort() {
		return oyaSort;
	}
	public void setOyaSort(String oyaSort) {
		this.oyaSort = oyaSort;
	}
	public Map<String, DataSchemaDetail> getDataSchemaDetailMap() {

		makeSchemaMap();
		return dataSchemaDetailMap;
	}



	public Map<String, DataDetail> getDataDetailMap() {

		makeDataDetailMap();
		return dataDetailMap;
	}

	private void makeDataDetailMap() {

		if (dataDetailMap == null) {

			dataDetailMap = new HashMap<String, DataDetail>();

			for (DataDetail detail : dataDetailList) {

				dataDetailMap.put(detail.getFieldKey(), detail);
			}
			for (DataDetail customDetail : customDataDetailList) {

				dataDetailMap.put(customDetail.getFieldKey(), customDetail);
			}


		}

	}

	private void makeSchemaMap() {

		if (dataSchemaDetailMap == null) {
			dataSchemaDetailMap = new HashMap<String, DataSchemaDetail>();
			for (DataSchemaDetail detail : schemaItemList) {
				dataSchemaDetailMap.put(detail.getFieldKey(), detail);
			}
			for (DataSchemaDetail customDetail : customItemList) {
				dataSchemaDetailMap.put(customDetail.getFieldKey(), customDetail);
			}
		}

	}
}
